<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/xhtml;charset=utf-8" http-equiv="Content-Type"/>
<meta content="IE=9" http-equiv="X-UA-Compatible"/>
<meta content="Doxygen 1.8.13" name="generator"/>
<title>OpenCV: Parallel backends API</title>
<link href="../../opencv.ico" rel="shortcut icon" type="image/x-icon"/>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script src="../../jquery.js" type="text/javascript"></script>
<script src="../../dynsections.js" type="text/javascript"></script>
<script src="../../tutorial-utils.js" type="text/javascript"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script src="../../search/searchdata.js" type="text/javascript"></script>
<script src="../../search/search.js" type="text/javascript"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
//<![CDATA[
MathJax.Hub.Config(
{
  TeX: {
      Macros: {
          matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
          fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
          forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
          forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
          vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
          vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
          cameramatrix: ["#1 = \\begin{bmatrix} f_x & 0 & c_x\\\\ 0 & f_y & c_y\\\\ 0 & 0 & 1 \\end{bmatrix}", 1],
          distcoeffs: ["(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \\tau_x, \\tau_y]]]]) \\text{ of 4, 5, 8, 12 or 14 elements}"],
          distcoeffsfisheye: ["(k_1, k_2, k_3, k_4)"],
          hdotsfor: ["\\dots", 1],
          mathbbm: ["\\mathbb{#1}", 1],
          bordermatrix: ["\\matrix{#1}", 1]
      }
  }
}
);
//]]>
</script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js" type="text/javascript"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css"/>
<link href="../../stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<!--#include virtual="/google-search.html"-->
<table cellpadding="0" cellspacing="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../opencv-logo-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenCV
    <span id="projectnumber">4.5.2</span>
   </div>
   <div id="projectbrief">Open Source Computer Vision</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
<script src="../../menudata.js" type="text/javascript"></script>
<script src="../../menu.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
  initMenu('../../',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow" onkeydown="return searchBox.OnSearchSelectKey(event)" onmouseout="return searchBox.OnSearchSelectHide()" onmouseover="return searchBox.OnSearchSelectShow()">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe frameborder="0" id="MSearchResults" name="MSearchResults" src="javascript:void(0)">
</iframe>
</div>
<div class="header">
  <div class="summary">
<a href="#nested-classes">Classes</a> |
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">Parallel backends API<div class="ingroups"><a class="el" href="../../d0/de1/group__core.html">Core functionality</a> » <a class="el" href="../../d3/d89/group__core__parallel.html">Parallel Processing</a></div></div>  </div>
</div><!--header-->
<div class="contents">
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="nested-classes"></a>
Classes</h2></td></tr>
<tr class="memitem:"><td align="right" class="memItemLeft" valign="top">class  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d9/dc9/classcv_1_1parallel_1_1ParallelForAPI.html">cv::parallel::ParallelForAPI</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:"><td align="right" class="memItemLeft" valign="top">class  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d0/d77/classcv_1_1parallel_1_1tbb_1_1ParallelForBackend.html">cv::parallel::tbb::ParallelForBackend</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:"><td align="right" class="memItemLeft" valign="top">class  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../dd/d8c/classcv_1_1parallel_1_1openmp_1_1ParallelForBackend.html">cv::parallel::openmp::ParallelForBackend</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga7791f3c18e50f00b5fa88ac9d44cd52f"><td align="right" class="memItemLeft" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../de/d55/group__core__parallel__backend.html#ga7791f3c18e50f00b5fa88ac9d44cd52f">cv::parallel::setParallelForBackend</a> (const std::shared_ptr&lt; <a class="el" href="../../d9/dc9/classcv_1_1parallel_1_1ParallelForAPI.html">ParallelForAPI</a> &gt; &amp;api, bool propagateNumThreads=true)</td></tr>
<tr class="memdesc:ga7791f3c18e50f00b5fa88ac9d44cd52f"><td class="mdescLeft"> </td><td class="mdescRight">Replace OpenCV parallel_for backend.  <a href="../../de/d55/group__core__parallel__backend.html#ga7791f3c18e50f00b5fa88ac9d44cd52f">More...</a><br/></td></tr>
<tr class="separator:ga7791f3c18e50f00b5fa88ac9d44cd52f"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:gad8733714032379c4801ae1807a4a1289"><td align="right" class="memItemLeft" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="../../de/d55/group__core__parallel__backend.html#gad8733714032379c4801ae1807a4a1289">cv::parallel::setParallelForBackend</a> (const std::string &amp;backendName, bool propagateNumThreads=true)</td></tr>
<tr class="memdesc:gad8733714032379c4801ae1807a4a1289"><td class="mdescLeft"> </td><td class="mdescRight">Change OpenCV parallel_for backend.  <a href="../../de/d55/group__core__parallel__backend.html#gad8733714032379c4801ae1807a4a1289">More...</a><br/></td></tr>
<tr class="separator:gad8733714032379c4801ae1807a4a1289"><td class="memSeparator" colspan="2"> </td></tr>
</table>
<a id="details" name="details"></a><h2 class="groupheader">Detailed Description</h2>
<p>API below is provided to resolve problem of CPU resource over-subscription by multiple thread pools from different multi-threading frameworks. This is common problem for cases when OpenCV compiled threading framework is different from the Users Applications framework.</p>
<p>Applications can replace OpenCV <code>parallel_for()</code> backend with own implementation (to reuse Application's thread pool).</p>
<h3>Backend API usage examples</h3>
<h4>Intel TBB</h4>
<ul>
<li>include header with simple implementation of TBB backend: <div class="fragment"><div class="line"><span class="preprocessor">#include "<a class="code" href="../../dd/d07/parallel__for_8tbb_8hpp.html">opencv2/core/parallel/backend/parallel_for.tbb.hpp</a>"</span></div></div><!-- fragment --></li>
<li>execute backend replacement code: <div class="fragment"><div class="line">    <a class="code" href="../../de/d55/group__core__parallel__backend.html#ga7791f3c18e50f00b5fa88ac9d44cd52f">cv::parallel::setParallelForBackend</a>(std::make_shared&lt;cv::parallel::tbb::ParallelForBackend&gt;());</div></div><!-- fragment --></li>
<li>configuration of compiler/linker options is responsibility of Application's scripts</li>
</ul>
<h4>OpenMP</h4>
<ul>
<li>include header with simple implementation of OpenMP backend: <div class="fragment"><div class="line"><span class="preprocessor">#include "<a class="code" href="../../dd/d5c/parallel__for_8openmp_8hpp.html">opencv2/core/parallel/backend/parallel_for.openmp.hpp</a>"</span></div></div><!-- fragment --></li>
<li>execute backend replacement code: <div class="fragment"><div class="line">    <span class="comment">//omp_set_dynamic(1);</span></div><div class="line">    <a class="code" href="../../de/d55/group__core__parallel__backend.html#ga7791f3c18e50f00b5fa88ac9d44cd52f">cv::parallel::setParallelForBackend</a>(std::make_shared&lt;cv::parallel::openmp::ParallelForBackend&gt;());</div></div><!-- fragment --></li>
<li>Configuration of compiler/linker options is responsibility of Application's scripts</li>
</ul>
<h3>Plugins support</h3>
<p>Runtime configuration options:</p><ul>
<li>change backend priority: <code>OPENCV_PARALLEL_PRIORITY_&lt;backend&gt;=9999</code></li>
<li>disable backend: <code>OPENCV_PARALLEL_PRIORITY_&lt;backend&gt;=0</code></li>
<li>specify list of backends with high priority (&gt;100000): <code>OPENCV_PARALLEL_PRIORITY_LIST=TBB,OPENMP</code>. Unknown backends are registered as new plugins. </li>
</ul>
<h2 class="groupheader">Function Documentation</h2>
<a id="ga7791f3c18e50f00b5fa88ac9d44cd52f"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga7791f3c18e50f00b5fa88ac9d44cd52f">◆ </a></span>setParallelForBackend() <span class="overload">[1/2]</span></h2>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void cv::parallel::setParallelForBackend </td>
          <td>(</td>
          <td class="paramtype">const std::shared_ptr&lt; <a class="el" href="../../d9/dc9/classcv_1_1parallel_1_1ParallelForAPI.html">ParallelForAPI</a> &gt; &amp; </td>
          <td class="paramname"><em>api</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool </td>
          <td class="paramname"><em>propagateNumThreads</em> = <code>true</code> </td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table><table class="python_language"><tr><th colspan="999" style="text-align:left">Python:</th></tr><tr><td style="width: 20px;"></td><td>retval</td><td>=</td><td>cv.parallel.setParallelForBackend(</td><td class="paramname">backendName[, propagateNumThreads]</td><td>)</td></tr></table>
</div><div class="memdoc">
<p><code>#include &lt;<a class="el" href="../../dc/d1b/parallel__backend_8hpp.html">opencv2/core/parallel/parallel_backend.hpp</a>&gt;</code></p>
<p>Replace OpenCV parallel_for backend. </p>
<p>Application can replace OpenCV <code>parallel_for()</code> backend with own implementation.</p>
<dl class="section note"><dt>Note</dt><dd>This call is not thread-safe. Consider calling this function from the <code>main()</code> before any other OpenCV processing functions (and without any other created threads). </dd></dl>
</div>
</div>
<a id="gad8733714032379c4801ae1807a4a1289"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gad8733714032379c4801ae1807a4a1289">◆ </a></span>setParallelForBackend() <span class="overload">[2/2]</span></h2>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool cv::parallel::setParallelForBackend </td>
          <td>(</td>
          <td class="paramtype">const std::string &amp; </td>
          <td class="paramname"><em>backendName</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool </td>
          <td class="paramname"><em>propagateNumThreads</em> = <code>true</code> </td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table><table class="python_language"><tr><th colspan="999" style="text-align:left">Python:</th></tr><tr><td style="width: 20px;"></td><td>retval</td><td>=</td><td>cv.parallel.setParallelForBackend(</td><td class="paramname">backendName[, propagateNumThreads]</td><td>)</td></tr></table>
</div><div class="memdoc">
<p><code>#include &lt;<a class="el" href="../../dc/d1b/parallel__backend_8hpp.html">opencv2/core/parallel/parallel_backend.hpp</a>&gt;</code></p>
<p>Change OpenCV parallel_for backend. </p>
<dl class="section note"><dt>Note</dt><dd>This call is not thread-safe. Consider calling this function from the <code>main()</code> before any other OpenCV processing functions (and without any other created threads). </dd></dl>
</div>
</div>
</div><!-- contents -->
<!-- HTML footer for doxygen 1.8.6-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 2 2021 11:36:40 for OpenCV by  <a href="http://www.doxygen.org/index.html">
<img alt="doxygen" class="footer" src="../../doxygen.png"/>
</a> 1.8.13
</small></address>
<script type="text/javascript">
//<![CDATA[
addTutorialsButtons();
//]]>
</script>
</body>
</html>
